@import '@devui/theme/styles-var/devui-var.scss';

$border-change-time: 300ms;
$border-change-function: cubic-bezier(0.645, 0.045, 0.355, 1);
$select-input-height-sm: $devui-size-sm;
$select-input-height-md: $devui-size-md;
$select-input-height-lg: $devui-size-lg;
$select-arrow-width: 28px;
$transition-base-time: 0.25s;
$select-dropdown-max-height: 300px;
$select-item-font-size: var(--devui-font-size, 12px);
$select-item-min-height: 36px;

@mixin border-transition {
  transition: border-color $border-change-time $border-change-function;
}

.#{$devui-prefix}-select {
  position: relative;
  width: 100%;
  font-size: $devui-font-size;

  &__selection {
    &:hover {
      border-color: $devui-form-control-line-hover;
    }
  }

  &--open,
  &--focus {
    .#{$devui-prefix}-select__selection:not(.#{$devui-prefix}-select__selection--error) {
      border-color: $devui-form-control-line-active;

      &:hover {
        border-color: $devui-form-control-line-active;
      }
    }
  }

  .#{$devui-prefix}-tag {
    margin: 4px 0 4px 4px;

    .#{$devui-prefix}-tag__item.#{$devui-prefix}-tag--md {
      height: 18px;
      line-height: 16px;
    }

    .#{$devui-prefix}-tag__item.#{$devui-prefix}-tag--default {
      background-color: $devui-label-bg;
    }
  }

  &--sm {
    font-size: $devui-font-size-sm;

    .#{$devui-prefix}-tag {
      margin: 2px 0 2px 4px;

      .#{$devui-prefix}-tag__item.#{$devui-prefix}-tag--sm {
        height: 18px;
        line-height: 16px;
      }
    }
  }

  &--lg {
    font-size: $devui-font-size-lg;
  }
}

.#{$devui-prefix}-select:not(.#{$devui-prefix}-select--disabled):not(.#{$devui-prefix}-select--underlined) {
  .#{$devui-prefix}-select__selection.#{$devui-prefix}-select__selection--glow-style {
    &:hover {
      border-color: $devui-form-control-line;
      box-shadow: 0 0 0 4px $devui-form-control-interactive-outline;
    }
    &.#{$devui-prefix}-select__selection--error:hover {
      border-color: $devui-danger-line;
      box-shadow: 0 0 0 4px $devui-form-control-interactive-outline;
    }
  }
}

.#{$devui-prefix}-select--open,
.#{$devui-prefix}-select--focus {
  .#{$devui-prefix}-select__selection.#{$devui-prefix}-select__selection--glow-style {
    border-color: $devui-form-control-line-active !important;
    box-shadow: 0 0 0 4px $devui-form-control-interactive-outline;

    &.#{$devui-prefix}-select__selection--error {
      border-color: $devui-danger-line;
    }
  }
}

.#{$devui-prefix}-select--underlined {
  border-bottom: 1px solid $devui-form-control-line;
  @include border-transition();

  &:not([disabled]):not(.disabled) {
    &:hover {
      border-color: $devui-form-control-line-hover;
    }

    &.#{$devui-prefix}-select--open {
      border-color: $devui-form-control-line-active;
    }
  }

  .#{$devui-prefix}-select__input,
  .#{$devui-prefix}-select__selection {
    border: none;
  }
}

.#{$devui-prefix}-select--disabled {
  cursor: not-allowed;
  background-color: $devui-disabled-bg;
  border-color: $devui-disabled-line;
  color: $devui-disabled-text;

  .#{$devui-prefix}-select__input,
  .#{$devui-prefix}-select__selection {
    cursor: not-allowed;
    background-color: $devui-disabled-bg;
    border-color: $devui-disabled-line;
    color: $devui-disabled-text;
  }

  .#{$devui-prefix}-select__arrow,
  .#{$devui-prefix}-select__clear {
    cursor: not-allowed;

    svg path {
      fill: $devui-disabled-text;
    }
  }
}

.#{$devui-prefix}-select--open {
  .#{$devui-prefix}-select__arrow {
    transform: rotate3d(0, 0, 1, 180deg);
  }
}

.#{$devui-prefix}-dropdown-menu-multiple {
  .#{$devui-prefix}-select__item {
    &.active {
      color: $devui-list-item-active-text;
      background-color: transparent;
    }
  }
}

.#{$devui-prefix}-select__selection {
  display: flex;
  align-items: center;
  position: relative;
  cursor: pointer;
  border: 1px solid $devui-form-control-line;
  border-radius: $devui-border-radius;
  background-color: $devui-form-control-bg;
  color: $devui-text;
  transition: border-color 0.3s $devui-animation-ease-in-out-smooth, box-shadow $devui-animation-duration-base $devui-animation-ease-in;

  &--error {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;

    &:hover {
      border-color: $devui-danger-line;
    }
  }
}

.#{$devui-prefix}-select__multiple {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding-right: 28px;
  cursor: pointer;

  .#{$devui-prefix}-select__multiple--input {
    display: flex;
    max-width: 100%;
    min-width: 15px;
  }
}

.#{$devui-prefix}-select__input {
  cursor: pointer;
  width: 100%;
  height: calc($select-input-height-md - 2px);
  padding: 4px $select-arrow-width 4px 10px;
  color: $devui-text;
  vertical-align: middle;
  outline: none;
  background: none;
  box-sizing: border-box;
  border: none;
  @include border-transition();

  &:not([disabled]):not(.disabled) {
    &:hover {
      border-color: $devui-form-control-line-hover;
    }

    &:focus {
      border-color: $devui-form-control-line-active;
    }
  }

  &[disabled],
  &.disabled {
    &:hover {
      cursor: not-allowed;
      background-color: $devui-disabled-bg;
      border-color: $devui-disabled-line;
      color: $devui-disabled-text;
    }
  }

  &.#{$devui-prefix}-select__input--lg {
    height: calc($select-input-height-lg - 2px);
  }

  &.#{$devui-prefix}-select__input--sm {
    height: calc($select-input-height-sm - 2px);
  }
}

.#{$devui-prefix}-select__clearable:hover {
  .#{$devui-prefix}-select__clear {
    display: inline-flex;
  }

  .#{$devui-prefix}-select__arrow {
    display: none;
  }
}

.#{$devui-prefix}-select__clear,
.#{$devui-prefix}-select__arrow {
  position: absolute;
  right: 0;
  height: 100%;
  width: $select-arrow-width;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.#{$devui-prefix}-select__clear {
  display: none;

  svg {
    path {
      fill: $devui-shape-icon-fill;
      transition: all $devui-animation-ease-in-out-smooth $devui-animation-duration-slow;
    }

    &:hover {
      path {
        fill: $devui-shape-icon-fill-hover;
      }
    }
  }
}

.#{$devui-prefix}-select__clear--feedback {
  right: 28px;
}

.#{$devui-prefix}-select__arrow {
  transform: rotate3d(0, 0, 1, 0deg);
  transition: transform $transition-base-time ease-out;

  svg path {
    fill: $devui-icon-text;
  }
}

.#{$devui-prefix}-select__arrow--feedback {
  right: 28px;
}

.#{$devui-prefix}-select__dropdown {
  overflow: auto;
}

.#{$devui-prefix}-select__dropdown-list {
  max-height: $select-dropdown-max-height;
  width: 100%;
  overflow-y: auto;
  padding: 0;
  margin: 0;
}

.#{$devui-prefix}-select__item {
  font-size: $select-item-font-size;
  display: block;
  min-height: $select-item-min-height;
  line-height: 1.5;
  width: 100%;
  padding: 8px 12px;
  clear: both;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border: 0;
  color: $devui-text;
  box-sizing: border-box;
  cursor: pointer;

  &:hover:not(.active):not(.disabled) {
    color: $devui-list-item-hover-text;
    background-color: $devui-list-item-hover-bg;
  }

  &.active {
    color: $devui-list-item-active-text;
    background-color: $devui-list-item-active-bg;
  }

  &.disabled {
    cursor: not-allowed;
    background-color: $devui-disabled-bg;
    color: $devui-disabled-text;
  }
}

.#{$devui-prefix}-select--sm .#{$devui-prefix}-select__item {
  font-size: $devui-font-size-sm;

  .#{$devui-prefix}-checkbox .#{$devui-prefix}-checkbox__material {
    width: $devui-font-size-sm;
    height: $devui-font-size-sm;

    & > svg {
      width: $devui-font-size-sm;
      height: $devui-font-size-sm;
    }
  }
}

.#{$devui-prefix}-select--lg .#{$devui-prefix}-select__item {
  font-size: $devui-font-size-lg;
  padding: 11px 10px;
}

.#{$devui-prefix}-scrollbar {
  &::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  &::-webkit-scrollbar-corner {
    background-color: transparent;
  }

  &::-webkit-scrollbar-thumb {
    border-radius: 8px;
    background-color: var(--devui-line, #adb0b8);
  }

  &::-webkit-scrollbar-track {
    background-color: transparent;
  }
}

.#{$devui-prefix}-select__dropdown--empty {
  text-align: center;
  font-size: $select-item-font-size;
  color: $devui-disabled-text;
  min-height: 22px;
}

.#{$devui-prefix}-select__group {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;

  &:not(:last-of-type) {
    padding-bottom: 24px;

    &::after {
      content: '';
      position: absolute;
      display: block;
      left: 12px;
      right: 12px;
      bottom: 12px;
      height: 1px;
      background: $devui-dividing-line;
    }
  }

  &-title {
    padding: 4px 12px;
    font-size: $select-item-font-size;
    color: $devui-aide-text;
  }
}

.fade {
  &-bottom {
    &-enter-from,
    &-leave-to {
      opacity: 0.8;
      transform: scaleY(0.8) translateY(-4px);
    }

    &-enter-to,
    &-leave-from {
      opacity: 1;
      transform: scaleY(0.9999) translateY(0);
    }

    &-enter-active {
      transition: transform 0.2s cubic-bezier(0.16, 0.75, 0.5, 1), opacity 0.2s cubic-bezier(0.16, 0.75, 0.5, 1);
    }

    &-leave-active {
      transition: transform 0.2s cubic-bezier(0.5, 0, 0.84, 0.25), opacity 0.2s cubic-bezier(0.5, 0, 0.84, 0.25);
    }
  }

  &-top {
    &-enter-from,
    &-leave-to {
      opacity: 0.8;
      transform: scaleY(0.8) translateY(4px);
    }

    &-enter-to,
    &-leave-from {
      opacity: 1;
      transform: scaleY(0.9999) translateY(0);
    }

    &-enter-active {
      transition: transform 0.2s cubic-bezier(0.16, 0.75, 0.5, 1), opacity 0.2s cubic-bezier(0.16, 0.75, 0.5, 1);
    }

    &-leave-active {
      transition: transform 0.2s cubic-bezier(0.5, 0, 0.84, 0.25), opacity 0.2s cubic-bezier(0.5, 0, 0.84, 0.25);
    }
  }
}
